/**
  ******************************************************************************
  * File Name          : steer.h
  * Description        : 用于舵机控制
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */
#ifndef __STEER_H
#define __STEER_H

#include "tim.h"
#include <stdint.h>

// constant

#define STEER_TIM (&htim3)
typedef enum
{
  GRIP_STEER_LEFT = TIM_CHANNEL_1,
  GRIP_STEER_RIGHT = TIM_CHANNEL_2,
  BOX_STEER_LEFT = TIM_CHANNEL_3,
  BOX_STEER_RIGHT = TIM_CHANNEL_4
} steer_t;

// angle and compare transform

#define STEER_MAX_COMPARE 600.0
#define STEER_MIN_COMPARE 100.0

#define STEER_MAX_ANGLE 180.0
#define STEER_MIN_ANGLE 0.0

#define ANGLE_TO_COMPARE(ang) (uint32_t)((ang * (STEER_MAX_COMPARE - STEER_MIN_COMPARE) / (STEER_MAX_ANGLE - STEER_MIN_ANGLE)) + STEER_MIN_COMPARE)
#define COMPARE_TO_ANGLE(cmp) (uint32_t)((cmp - STEER_MIN_COMPARE) * (STEER_MAX_ANGLE - STEER_MIN_ANGLE) / (STEER_MAX_COMPARE - STEER_MIN_COMPARE))

// function

void steer_init();
uint32_t steer_set_angle(steer_t steer, uint32_t angle);
uint32_t steer_get_angle(steer_t steer);

#endif